package com.controller;

import javax.xml.ws.RequestWrapper;

@Controller
public class UserController {
    @RequestMapping("/getUserId")
    public void getUserId(HttpServletRequest request){
        String userid = request.getParameter("userid");
        System.out.println("userid = " + userid);
    }
    @RequestMapping("/getUserNameAndId")
    public void getUserNameAndId(String username,Integer id){
        System.out.println("USERNAME = " + username + ", id = " + id);
    }
    @RequestMapping("/getUserName")
    public void getUserName(
            @RequestParam(value ="name", required = false, defaultValue = "itheima") String username
    ) {
        System.out.println("username = " + username + "id=" + id);
    }
    @RequestMapping("/registerUser")
    public void registerUser(User user){
        String name = user.getName();
        String password = user.getPassword();
        System.out.println("name = " + name);
        System.out.println("password = " + password);
    }
    @RequestMapping("/findOrderWithUser")
    public void findOr(User user){
        String username = user.getName();
        String orderId = user.getOrder().getOrderId();
        System.out.println("username = " + username);
        System.out.println("orderId = " + orderId);
    }
    @RequestMapping("/showPageByRequest")
    public String showPageByRequest(HttpServletRequest request){
        System.out.println("showPageByRequest running");
        request.setAttribute("username","张三");
        return "register";
    }
    @RequestMapping("/showPageModel")
    public String showPageByModel(Model model){
        model.addAttribute("username","model");
        User user = new User();
        user.setPassword("123456");
        model.addAttribute("user",user);
        return "register";
    }
    @RequestMapping("/showModelAndView")
    public ModelAndView showModelAndView(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username","黑马");
        User user = new User();
        user.setPassword("987654321");
        modelAndView.addObject("user",user);
        modelAndView.setViewName("register");// /WEB-INF/pages/register.jsp
        return modelAndView;
    }
}
